import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import menus from './modules/menu'

// console.log(app,'app');
// 自动导入 自动注册
const req = require.context('./modules', false, /\.js$/)
// console.log('req.keys  jsssss', req.keys());  // ['./app.js', './settings.js', './user.js']
// console.log('req.keys.map.req  jsssss', req.keys().map(req));

// console.log(req.keys().map(item=> item.split('./')[1] ).map(item=> item.split('.js')[0]));
// ['app', 'settings', 'user']
const mName = req.keys().map(item => item.split('./')[1]).map(item => item.split('.js')[0])
const mModule = req.keys().map(req) // [module,module,moduel]

const obj = {}
mName.forEach((key, index) => {
  obj[key] = mModule[index].default
})

// console.log('obj',obj);

Vue.use(Vuex)

const store = new Vuex.Store({
  modules: obj,
  getters,
  menus
})

export default store
